/*
    SUSAN® - Sole of Unix Save ANything

      Copyright (C) 2011-2016 Skyatlas Co. LTD

   Copyright (C) 2019-2020 Hechzh Property

   
*/

#include "stored/autochanger_resource.h"
#include "lib/alist.h"
#include "stored/device_resource.h"
#include "stored/stored_globals.h"

namespace storagedaemon {

AutochangerResource::AutochangerResource()
    : SusanResource()
    , device_resources(nullptr)
    , changer_name(nullptr)
    , changer_command(nullptr)
{
  return;
}

AutochangerResource& AutochangerResource::operator=(
    const AutochangerResource& rhs)
{
  SusanResource::operator=(rhs);
  device_resources = rhs.device_resources;
  changer_name = rhs.changer_name;
  changer_command = rhs.changer_command;
  changer_lock = rhs.changer_lock;
  return *this;
}

bool AutochangerResource::PrintConfig(OutputFormatterResource& send,
                                      const ConfigurationParser&,
                                      bool hide_sensitive_data,
                                      bool verbose)
{
  alist* original_alist = device_resources;
  alist* temp_alist = new alist(original_alist->size(), not_owned_by_alist);
  DeviceResource* device_resource = nullptr;
  foreach_alist (device_resource, original_alist) {
    if (device_resource->multiplied_device_resource) {
      if (device_resource->multiplied_device_resource == device_resource) {
        DeviceResource* d = new DeviceResource(*device_resource);
        d->MultipliedDeviceRestoreBaseName();
        temp_alist->append(d);
      }
    } else {
      DeviceResource* d = new DeviceResource(*device_resource);
      temp_alist->append(d);
    }
  }
  device_resources = temp_alist;
  SusanResource::PrintConfig(send, *my_config, hide_sensitive_data, verbose);
  device_resources = original_alist;
  foreach_alist (device_resource, temp_alist) {
    delete device_resource;
  }
  delete temp_alist;
  return true;
}

} /* namespace storagedaemon */
